# 输入第一个日期
date1 = input('请输入第一个日期（格式：YYYYMMDD）：')
year1 = int(date1[0:4])
month1 = int(date1[4:6])
day1 = int(date1[6:8])

# 输入第二个日期
date2 = input('请输入第二个日期（格式：YYYYMMDD）：')
year2 = int(date2[0:4])
month2 = int(date2[4:6])
day2 = int(date2[6:8])


def is_leap_year(year):
    return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)


def days_in_month(year, month):
    days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    if is_leap_year(year) and month == 2:
        return 29
    return days[month]


def day_of_year(year, month, day):
    result = 0
    for m in range(1, month):
        result += days_in_month(year, m)
    result += day
    return result


# 计算两个日期是该年的第几天
day_of_year1 = day_of_year(year1, month1, day1)
day_of_year2 = day_of_year(year2, month2, day2)

# 计算两个日期相差的天数
if year1 == year2:
    delta = abs(day_of_year1 - day_of_year2)
else:
    if year1 > year2:
        year1, year2 = year2, year1
        day_of_year1, day_of_year2 = day_of_year2, day_of_year1
    total_days = 0
    for y in range(year1, year2):
        total_days += 366 if is_leap_year(y) else 365
    delta = total_days - day_of_year1 + day_of_year2

print(f'{year1}年{month1}月{day1}日是{year1}年的第{day_of_year1}天')
print(f'{year2}年{month2}月{day2}日是{year2}年的第{day_of_year2}天')
print(f'两个日期相差 {delta} 天')